package cn.edu.nwafu.nic.nucleic_acid_test.controller;

import cn.edu.nwafu.nic.nucleic_acid_test.common.Result;
import cn.edu.nwafu.nic.nucleic_acid_test.services.FormDataService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author: SungLee
 * @date: 2022-02-19 19:21
 * @description: User相关的Controller
 */
@RestController
@RequestMapping("/api/form")
@Api(tags = "核酸检测数据统计相关接口")
public class FormDataController {
    private static final Logger logger = LoggerFactory.getLogger(FormDataController.class);
    @Autowired
    private FormDataService formDataService;

    @ApiOperation(value = "已检测总人数",notes="已检测总人数统计")
    @RequestMapping(path = "/counts/all", method = RequestMethod.GET)
    public Result testedCount() {
        Integer counts = formDataService.testedCount();
        return Result.success(counts.intValue());
    }

    @ApiOperation(value = "教职工汇总",notes="教职工检测情况汇总")
    @RequestMapping(path = "/counts/jzg", method = RequestMethod.GET)
    public Result jzgCount() {
        HashMap<String,Object> jzgCountMap = formDataService.jzgCount();
        return Result.success(jzgCountMap);
    }

    @ApiOperation(value = "本科生汇总",notes="本科生检测情况汇总")
    @RequestMapping(path = "/counts/bks", method = RequestMethod.GET)
    public Result bksCount() {
        HashMap<String,Object> bksCountMap = formDataService.bksCount();
        return Result.success(bksCountMap);
    }

    @ApiOperation(value = "研究生汇总",notes="教职工检测情况汇总")
    @RequestMapping(path = "/counts/yjs", method = RequestMethod.GET)
    public Result yjsCount() {
        HashMap<String,Object> yjsCountMap = formDataService.yjsCount();
        return Result.success(yjsCountMap);
    }

    @ApiOperation(value = "教职工数据统计",notes="教职工核酸检测数据按部门统计")
    @RequestMapping(path = "/statistics/jzg", method = RequestMethod.GET)
    public Result jzgTestedStatistics() {
        ArrayList<HashMap<String,Object>> jzgTestedStatisticsList = formDataService.jzgTestedStatistics();
        return Result.success(jzgTestedStatisticsList);
    }

    @ApiOperation(value = "本科生数据统计",notes="本科生核酸检测数据按部门统计")
    @RequestMapping(path = "/statistics/bks", method = RequestMethod.GET)
    public Result bksTestedStatistics() {
        ArrayList<HashMap<String,Object>> bksTestedStatisticsList = formDataService.bksTestedStatistics();
        return Result.success(bksTestedStatisticsList);
    }

    @ApiOperation(value = "研究生数据统计",notes="研究生核酸检测数据按部门统计")
    @RequestMapping(path = "/statistics/yjs", method = RequestMethod.GET)
    public Result yjsTestedStatistics() {
        ArrayList<HashMap<String,Object>> yjsTestedStatisticsList = formDataService.yjsTestedStatistics();
        return Result.success(yjsTestedStatisticsList);
    }

    @ApiOperation(value = "教职工未核酸人员列表",notes="教职工未参加核酸检测人员清单")
    @ApiImplicitParam(paramType = "query",name="dept",value = "所在单位",required = false,defaultValue = "")
    @RequestMapping(path = "/nottestlist/jzg", method = RequestMethod.GET)
    public Result jzgNotTestList(@RequestParam(value="dept",required=false,defaultValue = "") String dept) {
        ArrayList<HashMap<String,Object>> jzgNotTestList = formDataService.jzgNotTestList(dept);
        if (jzgNotTestList.size()==0){
            logger.error("查询结果为空");
            return Result.error(501,"参数有误，请核查",jzgNotTestList);
        }
        return Result.success(jzgNotTestList);
    }

    @ApiOperation(value = "本科生未核酸人员列表",notes="本科生未参加核酸检测人员清单")
    @ApiImplicitParam(paramType = "query",name="dept",value = "所在单位",required = false,defaultValue = "")
    @RequestMapping(path = "/nottestlist/bks", method = RequestMethod.GET)
    public Result bksNotTestList(@RequestParam(value="dept",required=false,defaultValue = "") String dept) {
        ArrayList<HashMap<String,Object>> bksNotTestList = formDataService.bksNotTestList(dept);
        if (bksNotTestList.size()==0){
            logger.error("查询结果为空");
            return Result.error(501,"参数有误，请核查",bksNotTestList);
        }
        return Result.success(bksNotTestList);
    }

    @ApiOperation(value = "研究生未核酸人员列表",notes="研究生未参加核酸检测人员清单")
    @ApiImplicitParam(paramType = "query",name="dept",value = "所在单位",required = false,defaultValue = "")
    @RequestMapping(path = "/nottestlist/yjs", method = RequestMethod.GET)
    public Result yjsNotTestList(@RequestParam(value="dept",required=false,defaultValue = "") String dept) {
        ArrayList<HashMap<String,Object>> yjsNotTestList = formDataService.yjsNotTestList(dept);
        if (yjsNotTestList.size()==0){
            logger.error("查询结果为空");
            return Result.error(501,"参数有误，请核查",yjsNotTestList);
        }
        return Result.success(yjsNotTestList);
    }
}
